<template>
	<view class="container">
		<view class="banner">
			<swiper class="swiper" indicator-dots="true" indicator-color=rgba(252,118,138,.5) indicator-active-color=rgba(252,118,138,1)
			 autoplay interval=3000 duration=800 circular>
				<swiper-item v-for="(item,index) in theList" :key="index" class="mySwiper">
					<!-- <view class="swiper-item uni-bg-red">{{item.content}}</view> -->
					<image :src="item.imgSrc" class="myPic"></image>
				</swiper-item>

			</swiper>
		</view>

		<view class="news">
			<view class="newLeft"></view>
			<view class="newRight">
				<swiper autoplay interval=2000 duration=800 circular class="news-swiper" vertical>
					<swiper-item class="news-swiper-item" v-for="(item,index) in newsLise" :key="index">
						<view class="newTitle">
							{{item.title}}
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>

		<view class="tools">
			<view class="tool" v-for="(item,index) in toolsList" :key="index">
				<view class="toolIcon">
					<image class="icon" :src="item.iconpath"></image>
				</view>
				<view class="toolName">
					{{item.toolName}}
				</view>
			</view>
		</view>

		<view class="waitLingyang">
			<view class="waithead">
				<view class="headleft">
					<view class="text">等待领养</view>
					<view class="headLogo">领养代替买卖</view>
				</view>
				<view class="headRight">
					<navigator url="../lingyang/lingyang" open-type="switchTab">
						<view class="rightText">
							更多
						</view>

						<view class="headRightArrow"></view>
					</navigator>
				</view>

			</view>

			<viwe class="cutePet">
				<scroll-view class="scrollBar" scroll-x="true">
					<view class="showBox" v-for="(item,index) in petList" :key="index">
						<image class="showBox-img" :src="item.p_showBoximg"></image>
						<view class="showBox-text">{{item.p_name}}</view>
						<view class="scrollButton">去领养</view>
					</view>
				</scroll-view>
			</viwe>
		</view>
	</view>
</template>

<script>
	let haha;
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				theList: [],
				sate: false,
				toolsList: [],
				newsLise: [{
						n_id: 1,
						title: "震惊，这么可爱的猫猫居然免费“送”，快来带回家",
						n_txt: ''
					},
					{
						n_id: 2,
						title: "震惊，这么可爱的狗狗居然免费“送”，快来带回家",
						n_txt: ''
					},
					{
						n_id: 3,
						title: "震惊，这么可爱的兔兔居然免费“送”，快来带回家",
						n_txt: ''
					},
					{
						n_id: 4,
						title: "震惊，这么可爱的狐狸居然免费“送”，快来带回家",
						n_txt: ''
					},
				],
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				petList: []
			}
		},
		created() {

		},
		onShow() {
			this.index();
			this.getToolsList();
			this.getPetList();

		},
		methods: {
			change(e) {
				this.current = e.detail.current;
			},
			index() {
				uniCloud.callFunction({
					name: 'lovepet_index',
					data: {}
				}).then((res) => {
					console.log('成功：', res)
					this.theList = res.result.data;

				}).catch((err) => {
					console.log('失败：', err)
				});

			},
			getToolsList() {
				uniCloud.callFunction({
					name: 'toolsList',
					data: {}
				}).then((res) => {
					console.log('成功：', res)
					this.toolsList = res.result.data;

					// console.log(this.toolsList);

				}).catch((err) => {
					console.log('失败：', err)
				})
			},
			getPetList() {
				uniCloud.callFunction({
					name: 'petList',
					data: {
						type: "get"
					}
				}).then((res) => {
					console.log('成功获取宠物列表：', res)
					console.log(res.result);
					this.petList = res.result.data;
					uni.setStorage({
						key: 'petList',
						data: res.result.data,
						success: function() {
							console.log('success存入', res.result.data);
						}
					});
				}).catch((err) => {
					console.log('失败：', err)
				})
			}

		},
		computed: {

		}
	}
</script>

<style>
	.rightText {
		float: left;
		margin-right: 2px;
		color: #ffaa00;
	}

	.headRight {
		height: 70rpx;
		/* background-color: #007AFF; */
		float: right;
		font-weight: 600;
		line-height: 70rpx;
		font-size: 11px;
	}

	.headRightArrow {
		width: 0px;
		height: 0px;
		border-width: 5px 0 5px 5px;
		border-color: transparent;
		border-style: solid;
		border-left-color: #ffaa00;
		float: left;
		margin-top: 13.4px;
		margin-right: 4rpx;
	}

	.headLogo {
		background-color: red;
		color: white;
		float: left;
		font-size: 10px;
		padding: 0 10rpx;
		border-radius: 10px;
		/* line-height: 70rpx; */
		height: 25px;
		margin-top: 5px;
	}

	.text {
		float: left;
		margin-right: 10rpx;
		font-weight: 600;
		line-height: 70rpx;
	}

	.headleft {
		float: left;
		height: 70rpx;
	}

	.waithead {
		width: 100%;
		height: 70rpx;
		/* background-color: #4CD964; */
		/* border-bottom: 1px solid pink; */
	}

	.waitLingyang {
		width: 90%;
		height: 450rpx;
		/* background-color: #2C405A; */
		margin: 10px auto;
		/* border: 1px solid pink; */
	}

	.icon {
		width: 90rpx;
		height: 90rpx;
	}

	.toolIcon {
		height: 90rpx;
		width: 90rpx;
		/* background-color: #4effe2; */
		margin: 5rpx auto;
	}

	.toolName {
		height: 50rpx;
		width: 100rpx;
		/* background-color: #333333; */
		margin: 0 auto;
		color: #666666;
		text-align: center;
		letter-spacing: 5rpx;
		line-height: 50rpx;
		font-size: 12px;
	}

	.news-swiper-item {
		color: #3F536E;
		font-size: 16px;
		font-weight: 500;
		line-height: 40rpx;
	}

	.news-swiper {
		width: 100%;
		height: 40rpx;
		margin: 30rpx 0;
		/* background-color: #007AFF; */
	}


	.newRight {
		height: 100rpx;
		width: calc(100% - 120rpx);
		float: left;
		/* background-color: #4CD964; */
	}

	.newLeft {
		width: 100rpx;
		height: 100rpx;
		margin-right: 10px;
		float: left;
		background-color: #2C405A;
		background-image: url(../../static/images/news/icon-news.png);
	}

	.tool {
		height: 150rpx;
		width: 150rpx;
		/* background-color: #007AFF; */
		border: 1px solid red;
		box-sizing: border-box;
	}

	.tools {
		width: 90%;
		height: 350rpx;
		/* background-color: #2C405A; */
		margin: 0 auto;
		display: flex;
		flex: 0 0 25%;
		flex-wrap: wrap;
		align-items: center;
		justify-content: space-evenly;
	}

	.container {
		/* padding: 20px; */
		font-size: 14px;
		line-height: 24px;
	}

	.banner {
		width: 90%;
		height: 400rpx;
		margin: 10px auto 0;
		/* background-color: pink; */
		/* overflow: hidden; */
	}

	.swiper {
		width: 675rpx;
		height: 400rpx;
		margin: 0 auto;
	}

	.mySwiper {
		width: 675rpx;
		height: 400rpx;
		margin: 0 auto;
		/* background-color: #007AFF; */
	}

	.myPic {
		width: 675rpx;
		height: 400rpx;
		object-fit: cover;
	}

	.myItem {
		width: 900rpx;
		height: 900rpx;
	}

	.news {
		width: 90%;
		height: 100rpx;
		margin: 10px auto;
		/* background-color: #007AFF; */
		box-shadow: #666666 3rpx 3rpx 10rpx;
	}

	.scrollBar {
		height: 380rpx;
		white-space: nowrap;
	}

	.showBox {
		width: 240rpx;
		height: 370rpx;
		/* background-color: #007AFF; */
		display: inline-block;
		margin-top: 5rpx;
		margin-right: 10px;
		box-shadow: 2px 2px 3px #c5c5c5;
		border-radius: 10px 10px 0 0;
		overflow: hidden;
	}

	.showBox-img {
		width: 240rpx;
		height: 240rpx;
		/* background-color: #4CD964; */
		display: block;
	}

	.showBox-text {
		height: 30rpx;
		width: 100%;
		text-align: center;
		line-height: 30rpx;
		font-size: 12px;
		/* background-color: #F0AD4E; */
		letter-spacing: 5rpx;
		padding: 10rpx 0;
	}

	.scrollButton {
		background-color: #FC768A;
		color: white;
		text-align: center;
		font-size: 11px;
		width: 120rpx;
		margin: 10px auto 0;
		border-radius: 10px;
	}
</style>
